var secureStore;
/*
 * This Method Load Secure Store so that we can access its getters setters
 */
function loadSWFStore() {
	secureStore = new SwfStore(
			{

				namespace : 'example7', // the this must match all other
										// instances that
				// want to share cookies

				swf_url : 'assets/flash/storage.swf', // to work cross-domain,
														// use the
				// same absolute url on both
				// pages (meaning
				// http://site.com/path/to/store.swf
				// not just /path/to.store.swf)

				debug : false, // depending on your browser, this will either
								// go to the
				// console or the bottom of the page.

				onready : function() {
					// now that the swfStore was loaded successfully, re-enable
					// everything
					// $('input').removeAttr("disabled");
					// $('#status').text('Loaded');
					var presentPageURL = window.location.href;
					
					try {
						if (presentPageURL.indexOf("index.html") != -1) {
							secureStore.set('camera1Id',"");
							secureStore.set('camera2Id',"");
							secureStore.set('invitedUserId',"");
							
							var camera1Id = getQueryVariable("camera1Id");
							var camera2Id = getQueryVariable("camera2Id");
							var invitedUserId = getQueryVariable("invitedUserId");
							
							secureStore.set('camera1Id',camera1Id);
							secureStore.set('camera2Id',camera2Id);
							secureStore.set('invitedUserId',invitedUserId);
							
							secureStore.set('userName',"");
							secureStore.set('id',"");	
							isLoginPage = true; 
						}
					} catch (e) {
					}
					

					var userName = secureStore.get('userName');
					
					try {
						if (userName && userName != undefined && userName != "") {
							
							var isLoginPage = false;

							try {
								if (presentPageURL.match(/\/$/)) {
									isLoginPage = true;
								}
							} catch (e) {
							}

							try {
								if (!isLoginPage
										&& (presentPageURL
												.match(/registration\.html$/) ||presentPageURL
												.indexOf("index.html") != -1 ||presentPageURL
												.match(/#$/) || presentPageURL
												.match(/SocialConnectCallback\.html$/))) {
									isLoginPage = true;
								}
							} catch (e) {
							}
							
							
							if (isLoginPage) {
								alert("Already Logged in!! Redirecting to Rate page");
								window.location.href="GadgetRocketGoal.html";
							}
						} else {
							var isLoginPage = false;

							try {
								if (presentPageURL.match(/\/$/) || presentPageURL.indexOf("index.html") != -1) {
									isLoginPage = true;
								}
							} catch (e) {
							}

							try {
								if (!isLoginPage
										&& (presentPageURL
												.match(/registration\.html$/) ||presentPageURL.indexOf("index.html") != -1 || presentPageURL.indexOf("AddFiles.html") != -1 ||presentPageURL
												.match(/#$/) || presentPageURL
												.match(/SocialConnectCallback\.html$/))) {
									isLoginPage = true;
								}
							} catch (e) {
							}

							if (!isLoginPage) {
								alert("No user logged in. Redirecting to Login page");
								window.location.href = "index.html";
							} else {
								// alert("Login using UserName password");
							}
						}
						
						if(onPersistantStoreLoaded){
							onPersistantStoreLoaded();
						}
					} catch (e) {
						alert("No user logged in. Redirecting to Login page");
						window.location.href = "index.html";
					}

					// read the existing value (if any)
					//$('#dataInput').val(mySwfStore.get('myValue'));

					// set up an onclick handler to save the text to the
					// swfStore
					// whenever the Save button is clicked
					// IE converts null to "null", so we're adding an `or "" `
					// to the
					// end to fix that
					//$('#saveBtn').click(function() {
					//	mySwfStore.set('myValue', $('#dataInput').val() || "");
					//	$('#status').text('Saved!')
					//});
				},

				onerror : function() {
					// in case we had an error. (The most common cause is that
					// the user
					// disabled flash cookies.)
					// $('#status').text('Error');
				}
			});

}

// wait until the page has finished loading before starting
$(function() {
	// first disable things while the swfStore is initializing
	// $('input').attr("disabled", "disabled");
	// $('#status').text('Loading...');
	loadSWFStore();
});